# -*- coding:utf-8 -*-

# str = "你好，世界;a"
# arr = str.split(";")
# print(arr)
#
import datetime
import json
import configparser
import random

import requests

# begin = '2018-06-14'
# end = '2018-12-31'
# # print(type(begin_date), begin_date)  # <class 'str'> 2017/01/01
#
# # 将 字符串开始日期 转成 日期格式   注意 : 格式一定要对应 /
# begin_date = datetime.datetime.strptime(begin, '%Y-%m-%d')
# print("开始:", begin_date)
# end_date = datetime.datetime.strptime(end, '%Y-%m-%d')
#
# print("结束:", end_date)

# with open("old_province.json", "r", encoding="UTF-8") as json_object:
#     list = json.load(json_object)
#     print(list)

# print(len("2014-12-10"))
# print("2014-12-10"[0:10])


# config = configparser.ConfigParser()
# config.read("config.ini")
# host = config.get("dbconfig", "host")
# user = config.get("dbconfig", "user")
# password = config.get("dbconfig", "password")
# db = config.get("dbconfig", "db")
# port = config.get("dbconfig", "port")
#
# print(host,user,password,db,port)


# now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S").replace("-", "").replace(":", "").replace(" ", "")
# print(now)

# Ⅰ、2=Ⅱ、3=Ⅲ
# import datetime
# print(datetime.datetime.now().timestamp())
# coding=utf-8import MySQLdb

# address = "河南省新乡市长垣市蒲东区内环路东侧647号"
#
# def check_data():
#     city = "新乡"
#     area = "-"
#     m = get_area_index(address, "市", 2)
#     n = get_area_index(address, "区", 2)
#     if "县" in address:
#         end_index = address.index("县")
#         start_index = end_index - 2
#         area = address[start_index:end_index]
#         if area in city:
#             area = "-"
#     elif m:
#         start_index = m - 2
#         area = address[start_index:m]
#         if area in city:
#             area = "-"
#     elif "市" in address:
#         end_index = address.index("市")
#         start_index = end_index - 2
#         area = address[start_index:end_index]
#         if area in city:
#             area = "-"
#     if area == "-" and "区" in address:
#         end_index = address.index("区")
#         start_index = end_index - 2
#         area = address[start_index:end_index]
#         if area in city:
#             area = "-"
#     print(area)
#
# def get_area_index(address, city, num):
#     count = address.count(city)
#     if count > 1:
#         i = 0
#         index = -1
#         while i < num:
#             index = address.find(city, index + 1)
#             i += 1
#         return index
#     else:
#         return None

import json
import xlrd


# def check_data():
#     wb1 = xlrd.open_workbook("地区为空-申通.xls")
#     sheet1 = wb1.sheet_by_index(0)
#     dataList = []
#     i = 0
#     while i < sheet1.nrows:
#         data = {}
#         data["enterprise_name"] = str(sheet1.row(i)[0].value)
#         data["province"] = str(int(sheet1.row(i)[1].value))
#         data["city"] = str(int(sheet1.row(i)[2].value))
#         data["area"] = str(int(sheet1.row(i)[3].value))
#         dataList.append(data)
#         i += 1
#     errorList = []
#     for i in dataList:
#         print(i)
#     with open("old_province.json", "r",encoding="UTF-8") as f:
#         city_data = json.load(f)
#         for data in dataList:
#             flag = False
#             for i in city_data:
#                 if flag:
#                     break
#                 if data["province"] == i["value"]:
#                     # data["province"] = i["value"]
#                     for j in i["children"]:
#                         if flag:
#                             break
#                         if data["city"] == j["value"]:
#                             # data["city"] = j["value"]
#                             if "children" in j.keys():
#                                 for k in j["children"]:
#                                     if data["area"] in k["value"]:
#                                         # data["area"] = k["value"]
#                                         flag = True
#                                         print("{}测试通过".format(data["enterprise_name"]))
#                                         break
#             if not flag:
#                 errorList.append(data["enterprise_name"])
#
#     with open("errorList.txt", "w") as ff:
#         for l in errorList:
#             ff.write(l + "\n")


def check_url():
    user_agent_pc = [
        # 谷歌
        'Mozilla/5.0.html (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.html.2171.71 Safari/537.36',
        'Mozilla/5.0.html (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.html.1271.64 Safari/537.11',
        'Mozilla/5.0.html (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.html.648.133 Safari/534.16',
        # 火狐
        'Mozilla/5.0.html (Windows NT 6.1; WOW64; rv:34.0.html) Gecko/20100101 Firefox/34.0.html',
        'Mozilla/5.0.html (X11; U; Linux x86_64; zh-CN; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10',
        # opera
        'Mozilla/5.0.html (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.html.2171.95 Safari/537.36 OPR/26.0.html.1656.60',
        # qq浏览器
        'Mozilla/5.0.html (compatible; MSIE 9.0.html; Windows NT 6.1; WOW64; Trident/5.0.html; SLCC2; .NET CLR 2.0.html.50727; .NET CLR 3.5.30729; .NET CLR 3.0.html.30729; Media Center PC 6.0.html; .NET4.0C; .NET4.0E; QQBrowser/7.0.html.3698.400)',
        # 搜狗浏览器
        'Mozilla/5.0.html (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.html.963.84 Safari/535.11 SE 2.X MetaSr 1.0.html',
        # 360浏览器
        'Mozilla/5.0.html (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.html.1599.101 Safari/537.36',
        'Mozilla/5.0.html (Windows NT 6.1; WOW64; Trident/7.0.html; rv:11.0.html) like Gecko',
        # uc浏览器
        'Mozilla/5.0.html (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.html.2125.122 UBrowser/4.0.html.3214.0.html Safari/537.36',
    ]
    result = 1
    try:
        headers = {
            'User-Agent': random.choice(user_agent_pc)
        }
        res = requests.get("http://www.abcdafdadfsda.com", timeout=0.5,headers=headers)
        print(res.status_code)
        print(res.text)
        # print(res.text)
    except:
        print("网站打不开")
        result = 2
    print(result)


if __name__ == '__main__':
    # check_data()
    check_url()
